"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
    return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (g && (g = 0, op[0] && (_ = 0)), _) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
    if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
        if (ar || !(i in from)) {
            if (!ar) ar = Array.prototype.slice.call(from, 0, i);
            ar[i] = from[i];
        }
    }
    return to.concat(ar || Array.prototype.slice.call(from));
};
Object.defineProperty(exports, "__esModule", { value: true });
var vue_1 = require("vue");
var spaceController_ts_1 = require("../api/spaceController.ts");
var vue_router_1 = require("vue-router");
var ant_design_vue_1 = require("ant-design-vue");
var space_1 = require("../constant/space");
var utils_1 = require("../utils");
var formData = (0, vue_1.reactive)({});
var loading = (0, vue_1.ref)(false);
var spaceLevelList = (0, vue_1.ref)([]);
var route = (0, vue_router_1.useRoute)();
var oldSpace = (0, vue_1.ref)();
// 空间类别,团队空间type=1，不传或0为私有空间
var spaceType = (0, vue_1.computed)(function () {
    var _a;
    if ((_a = route.query) === null || _a === void 0 ? void 0 : _a.type) {
        return Number(route.query.type);
    }
    return space_1.SPACE_TYPE_ENUM.PRIVATE;
});
// 获取空间级别
var fetchSpaceLevelList = function () { return __awaiter(void 0, void 0, void 0, function () {
    var res;
    return __generator(this, function (_a) {
        switch (_a.label) {
            case 0: return [4 /*yield*/, (0, spaceController_ts_1.listSpaceLevelUsingGet)()];
            case 1:
                res = _a.sent();
                if (res.data.code === 0 && res.data.data) {
                    spaceLevelList.value = res.data.data;
                }
                else {
                    ant_design_vue_1.message.error('加载空间级别失败，' + res.data.message);
                }
                return [2 /*return*/];
        }
    });
}); };
(0, vue_1.onMounted)(function () {
    fetchSpaceLevelList();
});
// 获取老数据，从而更新空间信息
var getOldSpace = function () { return __awaiter(void 0, void 0, void 0, function () {
    var id, res, data;
    var _a;
    return __generator(this, function (_b) {
        switch (_b.label) {
            case 0:
                id = (_a = route.query) === null || _a === void 0 ? void 0 : _a.id;
                if (!id) return [3 /*break*/, 2];
                return [4 /*yield*/, (0, spaceController_ts_1.getSpaceVoByIdUsingGet)({
                        id: id,
                    })];
            case 1:
                res = _b.sent();
                if (res.data.code === 0 && res.data.data) {
                    data = res.data.data;
                    oldSpace.value = data;
                    formData.spaceName = data.spaceName;
                    formData.spaceLevel = data.spaceLevel;
                }
                _b.label = 2;
            case 2: return [2 /*return*/];
        }
    });
}); };
// 页面加载时，请求老数据
(0, vue_1.onMounted)(function () {
    getOldSpace();
});
var handleSubmit = function (values) { return __awaiter(void 0, void 0, void 0, function () {
    var spaceId, res, path;
    var _a;
    return __generator(this, function (_b) {
        switch (_b.label) {
            case 0:
                spaceId = (_a = oldSpace.value) === null || _a === void 0 ? void 0 : _a.id;
                loading.value = true;
                if (!spaceId) return [3 /*break*/, 2];
                return [4 /*yield*/, (0, spaceController_ts_1.updateSpaceUsingPost)(__assign({ id: spaceId }, formData))];
            case 1:
                res = _b.sent();
                return [3 /*break*/, 4];
            case 2: return [4 /*yield*/, (0, spaceController_ts_1.addSpaceUsingPost)(__assign(__assign({}, formData), { spaceType: spaceType.value }))];
            case 3:
                // 创建
                res = _b.sent();
                _b.label = 4;
            case 4:
                if (res.data.code === 0 && res.data.data) {
                    ant_design_vue_1.message.success('操作成功');
                    path = "/space/".concat(spaceId !== null && spaceId !== void 0 ? spaceId : res.data.data);
                    router.push({
                        path: path,
                    });
                }
                else {
                    ant_design_vue_1.message.error('操作失败，' + res.data.message);
                }
                loading.value = false;
                return [2 /*return*/];
        }
    });
}); }; /* PartiallyEnd: #3632/scriptSetup.vue */
function __VLS_template() {
    var _a;
    var __VLS_ctx = {};
    var __VLS_components;
    var __VLS_directives;
    // CSS variable injection 
    // CSS variable injection end 
    __VLS_elementAsFunction(__VLS_intrinsicElements.div, __VLS_intrinsicElements.div)({
        id: ("addSpacePage"),
    });
    __VLS_elementAsFunction(__VLS_intrinsicElements.h2, __VLS_intrinsicElements.h2)(__assign({ style: ({}) }));
    (((_a = __VLS_ctx.route.query) === null || _a === void 0 ? void 0 : _a.id) ? '修改' : '创建');
    (__VLS_ctx.SPACE_TYPE_MAP[__VLS_ctx.spaceType]);
    var __VLS_0 = {}.AForm;
    /** @type { [typeof __VLS_components.AForm, typeof __VLS_components.aForm, typeof __VLS_components.AForm, typeof __VLS_components.aForm, ] } */ ;
    // @ts-ignore
    var __VLS_1 = __VLS_asFunctionalComponent(__VLS_0, new __VLS_0(__assign({ 'onFinish': {} }, { layout: ("vertical"), model: ((__VLS_ctx.formData)) })));
    var __VLS_2 = __VLS_1.apply(void 0, __spreadArray([__assign({ 'onFinish': {} }, { layout: ("vertical"), model: ((__VLS_ctx.formData)) })], __VLS_functionalComponentArgsRest(__VLS_1), false));
    var __VLS_6;
    var __VLS_7 = {
        onFinish: (__VLS_ctx.handleSubmit)
    };
    var __VLS_3;
    var __VLS_4;
    var __VLS_8 = {}.AFormItem;
    /** @type { [typeof __VLS_components.AFormItem, typeof __VLS_components.aFormItem, typeof __VLS_components.AFormItem, typeof __VLS_components.aFormItem, ] } */ ;
    // @ts-ignore
    var __VLS_9 = __VLS_asFunctionalComponent(__VLS_8, new __VLS_8({
        label: ("空间名称"),
        name: ("spaceName"),
    }));
    var __VLS_10 = __VLS_9.apply(void 0, __spreadArray([{
            label: ("空间名称"),
            name: ("spaceName"),
        }], __VLS_functionalComponentArgsRest(__VLS_9), false));
    var __VLS_14 = {}.AInput;
    /** @type { [typeof __VLS_components.AInput, typeof __VLS_components.aInput, ] } */ ;
    // @ts-ignore
    var __VLS_15 = __VLS_asFunctionalComponent(__VLS_14, new __VLS_14({
        value: ((__VLS_ctx.formData.spaceName)),
        placeholder: ("请输入空间名称"),
        allowClear: (true),
    }));
    var __VLS_16 = __VLS_15.apply(void 0, __spreadArray([{
            value: ((__VLS_ctx.formData.spaceName)),
            placeholder: ("请输入空间名称"),
            allowClear: (true),
        }], __VLS_functionalComponentArgsRest(__VLS_15), false));
    __VLS_13.slots.default;
    var __VLS_13;
    var __VLS_20 = {}.AFormItem;
    /** @type { [typeof __VLS_components.AFormItem, typeof __VLS_components.aFormItem, typeof __VLS_components.AFormItem, typeof __VLS_components.aFormItem, ] } */ ;
    // @ts-ignore
    var __VLS_21 = __VLS_asFunctionalComponent(__VLS_20, new __VLS_20({
        label: ("空间级别"),
        name: ("spaceLevel"),
    }));
    var __VLS_22 = __VLS_21.apply(void 0, __spreadArray([{
            label: ("空间级别"),
            name: ("spaceLevel"),
        }], __VLS_functionalComponentArgsRest(__VLS_21), false));
    var __VLS_26 = {}.ASelect;
    /** @type { [typeof __VLS_components.ASelect, typeof __VLS_components.aSelect, ] } */ ;
    // @ts-ignore
    var __VLS_27 = __VLS_asFunctionalComponent(__VLS_26, new __VLS_26(__assign(__assign({ value: ((__VLS_ctx.formData.spaceLevel)), options: ((__VLS_ctx.SPACE_LEVEL_OPTIONS)), placeholder: ("请输入空间级别") }, { style: ({}) }), { allowClear: (true) })));
    var __VLS_28 = __VLS_27.apply(void 0, __spreadArray([__assign(__assign({ value: ((__VLS_ctx.formData.spaceLevel)), options: ((__VLS_ctx.SPACE_LEVEL_OPTIONS)), placeholder: ("请输入空间级别") }, { style: ({}) }), { allowClear: (true) })], __VLS_functionalComponentArgsRest(__VLS_27), false));
    __VLS_25.slots.default;
    var __VLS_25;
    var __VLS_32 = {}.AFormItem;
    /** @type { [typeof __VLS_components.AFormItem, typeof __VLS_components.aFormItem, typeof __VLS_components.AFormItem, typeof __VLS_components.aFormItem, ] } */ ;
    // @ts-ignore
    var __VLS_33 = __VLS_asFunctionalComponent(__VLS_32, new __VLS_32({}));
    var __VLS_34 = __VLS_33.apply(void 0, __spreadArray([{}], __VLS_functionalComponentArgsRest(__VLS_33), false));
    var __VLS_38 = {}.AButton;
    /** @type { [typeof __VLS_components.AButton, typeof __VLS_components.aButton, typeof __VLS_components.AButton, typeof __VLS_components.aButton, ] } */ ;
    // @ts-ignore
    var __VLS_39 = __VLS_asFunctionalComponent(__VLS_38, new __VLS_38(__assign(__assign({ type: ("primary"), htmlType: ("submit") }, { style: ({}) }), { loading: ((__VLS_ctx.loading)) })));
    var __VLS_40 = __VLS_39.apply(void 0, __spreadArray([__assign(__assign({ type: ("primary"), htmlType: ("submit") }, { style: ({}) }), { loading: ((__VLS_ctx.loading)) })], __VLS_functionalComponentArgsRest(__VLS_39), false));
    __VLS_43.slots.default;
    var __VLS_43;
    __VLS_37.slots.default;
    var __VLS_37;
    __VLS_5.slots.default;
    var __VLS_5;
    var __VLS_44 = {}.ACard;
    /** @type { [typeof __VLS_components.ACard, typeof __VLS_components.aCard, typeof __VLS_components.ACard, typeof __VLS_components.aCard, ] } */ ;
    // @ts-ignore
    var __VLS_45 = __VLS_asFunctionalComponent(__VLS_44, new __VLS_44({
        title: ("空间级别介绍"),
    }));
    var __VLS_46 = __VLS_45.apply(void 0, __spreadArray([{
            title: ("空间级别介绍"),
        }], __VLS_functionalComponentArgsRest(__VLS_45), false));
    var __VLS_50 = {}.ATypographyParagraph;
    /** @type { [typeof __VLS_components.ATypographyParagraph, typeof __VLS_components.aTypographyParagraph, typeof __VLS_components.ATypographyParagraph, typeof __VLS_components.aTypographyParagraph, ] } */ ;
    // @ts-ignore
    var __VLS_51 = __VLS_asFunctionalComponent(__VLS_50, new __VLS_50({}));
    var __VLS_52 = __VLS_51.apply(void 0, __spreadArray([{}], __VLS_functionalComponentArgsRest(__VLS_51), false));
    __VLS_elementAsFunction(__VLS_intrinsicElements.a, __VLS_intrinsicElements.a)({
        href: ("https://codefather.cn"),
        target: ("_blank"),
    });
    __VLS_55.slots.default;
    var __VLS_55;
    for (var _i = 0, _b = __VLS_getVForSourceType((__VLS_ctx.spaceLevelList)); _i < _b.length; _i++) {
        var spaceLevel = _b[_i][0];
        var __VLS_56 = {}.ATypographyParagraph;
        /** @type { [typeof __VLS_components.ATypographyParagraph, typeof __VLS_components.aTypographyParagraph, typeof __VLS_components.ATypographyParagraph, typeof __VLS_components.aTypographyParagraph, ] } */ ;
        // @ts-ignore
        var __VLS_57 = __VLS_asFunctionalComponent(__VLS_56, new __VLS_56({}));
        var __VLS_58 = __VLS_57.apply(void 0, __spreadArray([{}], __VLS_functionalComponentArgsRest(__VLS_57), false));
        (spaceLevel.text);
        (__VLS_ctx.formatSize(spaceLevel.maxSize));
        (spaceLevel.maxCount);
        __VLS_61.slots.default;
        var __VLS_61;
    }
    __VLS_49.slots.default;
    var __VLS_49;
    var __VLS_slots;
    var $slots;
    var __VLS_inheritedAttrs;
    var $attrs;
    var __VLS_refs = {};
    var $refs;
    var $el;
    return {
        attrs: {},
        slots: __VLS_slots,
        refs: $refs,
        rootEl: $el,
    };
}
;
var __VLS_self = (await Promise.resolve().then(function () { return __importStar(require('vue')); })).defineComponent({
    setup: function () {
        return {
            SPACE_LEVEL_OPTIONS: space_1.SPACE_LEVEL_OPTIONS,
            SPACE_TYPE_MAP: space_1.SPACE_TYPE_MAP,
            formatSize: utils_1.formatSize,
            formData: formData,
            loading: loading,
            spaceLevelList: spaceLevelList,
            route: route,
            spaceType: spaceType,
            handleSubmit: handleSubmit,
        };
    },
});
exports.default = (await Promise.resolve().then(function () { return __importStar(require('vue')); })).defineComponent({
    setup: function () {
        return {};
    },
    __typeEl: {},
});
; /* PartiallyEnd: #4569/main.vue */
